################################################################################
# Judicial Ideology as Text -- Table 1 (Literature Review -- Bonica & Sen 2021)
# Truscott & Romano
# Updated February 2025
################################################################################

################################################################################
# Necessary Packages & Dependencies
################################################################################

source('R/truscott_romano_source.R')


################################################################################
# Table A1: Weights Classifications
################################################################################

type = c("Segal-Cover", "Martin-Quinn", "Appointment Indicators", "DIME")
data = c(
  "Pre-confirmation newspaper coverage from Conservative and Liberal news editorials.",
  "Observed votes in cases.",
  "Party or Ideal-Point proxies.",
  "Campaign contributions of federal judges or law clerks as proxy."
)
strengths = c(
  "- Uses external information to predict ideology.\n- Draws on expertise of Court observers (and reporters) to characterize a nominee’s partisanship.\n- Strong correlation between scores and votes on the Court (Segal and Cover 1989, p. 561).",
  "- Estimates relative measures of judicial ideology with uncertainty. Proven to be a reliable approach across other literatures, particularly Congressional ideology (e.g., Clinton, Jackman, and Rivers 2004).\n- Relies on observable behaviors (votes), rather than inferring ideology from (potentially subjective) characterizations.",
  "- Appointments to the federal bench are guided by a president’s desire to appoint like-minded jurists, notwithstanding potential constraints by the Senate.\n- Adequate correlation, particularly when politically divisive issues tend to fall along general notions of Liberal versus Conservative perspectives.",
  "- Approximately 80 percent of federal appeals judges contributed to campaigns between 2001 and 2016 (Bonica and Sen 2017).\n- Draws on dynamic behaviors of hired law clerks to account for missingness. Because new clerks are hired yearly, the scores are dynamic and comparable across longitudinal observations.\n- Allows for variance in ideology – e.g., those who give more to strong partisans than moderate partisans will be reflected accordingly."
)
critiques = c(
  "- Scores are static, whereas judicial ideology is known to ‘drift’ (i.e., change) over time (e.g., Owens and Wedeking 2012; Epstein, Martin, Quinn, and Segal 2007).\n- Requires an extensive volume of pre-confirmation information.\n- Requires subjective assessment of ideology.",
  "- Only feasible if cases decided together as a single body – not transferable across dynamic, cross-sectional observations or directly comparable to other courts.\n- Endogeneity Concern: Random walk prior from preceding term used to guide estimation but using MQ to predict votes places voting behaviors as both a DV and IV.\n- Unidimensional and assumes “the distribution of cases characteristics is constant over time” (Ho and Quinn 2010).",
  "- Assumes that Democratic appointees are inherently more liberal while Republicans more conservative.\n- Assumes that the constraints of judicial appointments (e.g., senatorial courtesy and conditions of unified vs. divided government) are sufficient to predict distinct, judge-level variance in ideology.\n- Considerable variation in behaviors, even among those appointed by the same president.",
  "- Represents an indirect measure of ideology for judges who do not contribute to campaigns – Particularly for Supreme Court Justices.\n- Assumes that judges generally hire like-minded clerks (though they account for this by averaging scores across clerks)."
)

lit_review <- data.frame()

for (t in 1:length(type)){

  temp <- data.frame(type = type[t],
                     data = data[t],
                     strengths = strengths[t],
                     critiques = critiques[t])

  num_strengths <- length(unlist(strsplit(temp$strengths, split = '\n')))
  num_critiques <- length(unlist(strsplit(temp$critiques, split = '\n')))
  temp_strengths <- unlist(strsplit(temp$strengths, split = '\n'))
  temp_critiques <- unlist(strsplit(temp$critiques, split = '\n'))

  temp_matrix <- matrix(ncol = 4, nrow = max(c(num_strengths, num_critiques)))

  temp_matrix[1,1] <- temp$type
  temp_matrix[1,2] <- temp$data
  temp_matrix[c(1:num_strengths), 3] <- temp_strengths
  temp_matrix[c(1:num_critiques), 4] <- temp_critiques

  temp_df <- data.frame(temp_matrix)
  names(temp_df) <- c('Type', 'Data', 'Strengths', 'Critiques')
  temp_df <- temp_df %>% mutate(across(everything(), ~ replace_na(.x, "")))


  lit_review <- bind_rows(lit_review, temp_df)

}

lit_review <- tibble::tibble(lit_review)


table_1_text <- stargazer(lit_review, type = 'text', summary = F, rownames = F)
table_1_latex <- stargazer(lit_review, type = 'latex', summary = F, rownames = F, label = 'tab:table_A1', title = 'Associative Weighting Schemes by Opinion Authorship', style = 'apsr')

writeLines(table_1_text, 'tables/table_1_text.txt', sep = '\n')
writeLines(table_1_latex, 'tables/table_1_latex.txt', sep = '\n')

rm(critiques, strengths, data, num_critiques, num_strengths, t, temp_critiques, temp_strengths, type, lit_review, temp, temp_df, temp_matrix)

